//
//  HLCourseCollectionCell.m
//  HLAerospace
//
//  Created by hulian-iOS on 17/9/21.
//  Copyright © 2017年 李斌. All rights reserved.
//

#import "HLCourseCollectionCell.h"
#import <Masonry/Masonry.h>
#import <SDWebImage/UIImageView+WebCache.h>
#import "HLMoreCourse.h"
#import "HLCollect.h"

@interface HLCourseCollectionCell ()

/** ImageView  */
@property (nonatomic ,strong) UIImageView *iconView;
/** title  */
@property (nonatomic ,strong) UILabel *title;
/** seeNum  */
@property (nonatomic ,strong) UILabel *seeNum;

/** categaryIconView  */
@property (nonatomic ,strong) UILabel *categaryTitle;

@end

@implementation HLCourseCollectionCell


- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self setupUI];
    }
    return self;
}


- (UILabel *)categaryTitle
{
    if (!_categaryTitle ) {
        _categaryTitle = [[UILabel alloc] init];
        _categaryTitle.textAlignment = NSTextAlignmentCenter;
        _categaryTitle.backgroundColor = kColorMineBlueBG;
        _categaryTitle.textColor = [UIColor whiteColor];
        _categaryTitle.font = [UIFont boldSystemFontOfSize:IS_IPHONE_5 ? 11: 13];
    }
    return _categaryTitle;
}

- (UIImageView *)iconView
{
    if (!_iconView ) {
        _iconView = [[UIImageView alloc] init];
        _iconView.layer.cornerRadius = 3;
        _iconView.clipsToBounds = YES;
        
    }
    return _iconView;
}

- (UILabel *)title
{
    if (!_title ) {
        _title = [[UILabel alloc] init];
        _title.backgroundColor = [UIColor clearColor];
        _title.textColor = HLRGB(60, 60, 60);
        _title.font = [UIFont systemFontOfSize:IS_IPHONE_5 ? 12: kMainTitleFontSize];
    }
    return _title;
}

- (UILabel *)seeNum
{
    if (!_seeNum) {
        _seeNum = [[UILabel alloc]init];
        _seeNum.backgroundColor = [UIColor clearColor];
        _seeNum.textColor = HLRGB(120, 120, 120);
        _seeNum.font = [UIFont systemFontOfSize:IS_IPHONE_5 ? 11: 14];
    }
    return _seeNum;
}


- (void)setupUI
{
    [self addSubview:self.iconView];
    [self.iconView addSubview:self.categaryTitle];
    [self addSubview:self.title];
    [self addSubview:self.seeNum];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.left.equalTo(self);
        make.right.equalTo(self);
        make.height.equalTo(@(self.height * 0.7));
    }];
    
    [self.categaryTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(16));
        make.top.equalTo(self.iconView);
        make.right.equalTo(self.iconView);
        make.width.equalTo(@(35));
    }];
    
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconView.mas_bottom);
        make.left.equalTo(self);
        make.width.equalTo(self);
        make.height.equalTo(@(self.height * 0.18));
        
    }];
    
    [self.seeNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.title.mas_bottom);
        make.left.equalTo(self);
        make.width.equalTo(self);
        make.height.equalTo(@(self.height * 0.12));
    }];
    
}

- (void)setMoreCourse:(HLMoreCourse *)moreCourse
{
    _moreCourse = moreCourse;
    
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:moreCourse.pic] placeholderImage:nil];
    self.title.text = moreCourse.name;
    self.seeNum.text = moreCourse.num.length == 0 ? @"0人浏览" :[NSString stringWithFormat:@"%@人浏览",moreCourse.num];
    self.categaryTitle.text = [moreCourse.type integerValue] == 0 ? @"视频":@"文章";
}

@end
